package com.ideaaedi.zoo.example.springboot.seata.alpha.feign;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import io.seata.core.context.RootContext;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 手动传递全局事务id的方式
 */
@Service
public class RawHttpRequest4 {
    
    /**
     * 随机添加角色
     */
    public void randomAddRole() {
        HttpRequest httpRequest = HttpUtil.createGet("http://127.0.0.1:8081/role/random-add");
        // 获取 全局事务id
        String currentXid = RootContext.getXID();
        if (StringUtils.isNotBlank(currentXid)) {
            httpRequest.header(RootContext.KEY_XID, currentXid);
        }
        httpRequest.execute();
    }
}
